<template>
  <div class="login-wrap">
    <el-form class="login-form" label-position="top" label-width="80px" :model="formData">
      <h2>用户登录</h2>
      <el-form-item label="用户名">
        <el-input v-model="formData.loginName"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input type="password" v-model="formData.password"></el-input>
      </el-form-item>
      <el-button @click="handleLogin" class="login-button" type="primary">登录</el-button>
    </el-form>
  </div>
</template>
<script>
import $$ from '@/plugins/statusCode.config'
export default {
  data () {
    return {
      formData: {
        loginName: '',
        password: ''
      }
    }
  },
  methods: {
    async handleLogin () {
      if (this.formData.password && this.formData.loginName) {
        let param = new URLSearchParams()
        const that = this
        param.append('loginName', this.formData.loginName)
        param.append('password', this.formData.password)
        await this.$http8081
          .post(`/manager-search/login`, param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70000) {
              that.$message.success(res.data.statusMsg)
              that.$router.push({ name: 'index' })
            } else {
              return that.$message.warning(res.data.statusMsg)
            }
          })
      } else {
        return this.$message.warning('请填写完整信息')
      }
    },
    async searchRoleToMySelf () {
      if (this.formData.password && this.formData.loginName) {
        let param = new URLSearchParams()
        const that = this
        param.append('loginName', this.formData.loginName)
        param.append('password', this.formData.password)
        await this.$http8081
          .post(`/manager-search/login`, param)
          .then(function (res) {
            if (res.data.statusCode === $$.s70000) {
              that.$message.success(res.data.statusMsg)
              that.$router.push({ name: 'index' })
            } else {
              return that.$message.warning(res.data.statusMsg)
            }
          })
      } else {
        return this.$message.warning('请填写完整信息')
      }
    }
  }
}
</script>
<style>
.login-wrap {
  background-color: rgb(84, 92, 100);
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.login-wrap .login-form {
  background-color: #fff;
  width: 400px;
  padding: 30px;
  border-radius: 5px;
}

.login-wrap .login-form .login-button {
  width: 100%;
}
</style>
